package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceSerVice;
import com.zzyl.vo.DeviceDataVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/iot")
@Api("设备管理相关接口")
@Slf4j
public class DeviceController {

    @Autowired
    private DeviceSerVice deviceSerVice;

    /**
     * 从物联网平台同步产品列表
     * @return
     */
    @PostMapping("/syncProductList")
    @ApiOperation("从物联网平台同步产品列表")
    private ResponseResult getSyncProductList(){
        deviceSerVice.getSyncProductList();
        return ResponseResult.success();
    }

    /**
     * 查询所有产品列表
     * @return
     */
    @GetMapping("/allProduct")
    @ApiOperation("查询所有产品列表")
    private ResponseResult<List<ProductVo>> getProductList(){
        List<ProductVo> productVos = deviceSerVice.getProductList();
        return ResponseResult.success(productVos);
    }


    /**
     * 注册设备
     * @param deviceDto
     * @return
     */
    @ApiOperation("注册设备")
    @PostMapping("/RegisterDevice")
    private ResponseResult RegisterDevice(@RequestBody @ApiParam("注册设备信息") DeviceDto deviceDto){
        deviceSerVice.RegisterDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 分页查询设备列表
     * @param devicePageQueryDto
     * @return
     */
    @ApiOperation("分页查询设备列表")
    @GetMapping("/pageQueryDevice")
    private ResponseResult<PageResponse> queryPageDevice(@ModelAttribute @ApiParam("查询设备信息") DevicePageQueryDto devicePageQueryDto){
        PageResponse pageResponse = deviceSerVice.queryPageDevice(devicePageQueryDto);
        System.out.println(pageResponse);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 查询设备详细数据
     * @param deviceDto
     * @return
     */
    @ApiOperation("查询设备详细数据")
    @PostMapping("/QueryDeviceDetail")
    private ResponseResult<DeviceVo> QueryDeviceDetail(@RequestBody @ApiParam("查询信息") DeviceDto deviceDto){
        DeviceVo deviceVo = deviceSerVice.QueryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    /**
     * 查询指定设备的物模型的运行状态
     * @param deviceDto
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询指定设备的物模型运行状态")
    private ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> queryDeviceStatus(@RequestBody @ApiParam("查询信息") DeviceDto deviceDto){
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData queryDevicePropertyStatusResponseBodyData = deviceSerVice.queryDeviceStatus(deviceDto);
        return ResponseResult.success(queryDevicePropertyStatusResponseBodyData);
    }

    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param deviceDto
     * @return
     */
    @ApiOperation("查看指定产品的已发布物模型中的功能定义详情")
    @PostMapping("/QueryThingModelPublished")
    private ResponseResult<Map<String,String>> QueryThingModelPublished(@RequestBody DeviceDto deviceDto){
        Map<String,String> map = deviceSerVice.QueryThingModelPublished(deviceDto);
        return ResponseResult.success(map);
    }

    /**
     * 修改设备备注名称
     * @param deviceDto
     * @return
     */
    @PostMapping("/UpdateDevice")
    @ApiOperation("修改设备备注名称")
    private ResponseResult UpdateDevice(@RequestBody @ApiParam("修改设备备注名称") DeviceDto deviceDto){
        deviceSerVice.UpdateDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 删除设备
     * @param deviceDto
     * @return
     */
    @ApiOperation("删除设备")
    @DeleteMapping("/DeleteDevice")
    private ResponseResult deleteDevice(@RequestBody @ApiParam("删除信息") DeviceDto deviceDto ){
        deviceSerVice.deleteDevice(deviceDto);
        return ResponseResult.success();
    }



}
